package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.dao.impl.StationDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/courierStation/modifyCourierStation")
public class UpdateStateServlet extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String courierStationId = req.getParameter("courierStationId");
        String courierStationStatus = req.getParameter("courierStationStatus");
        int id=Integer.parseInt(courierStationId);
        int status=Integer.parseInt(courierStationStatus);
        StationDaoImpl stationDao=new StationDaoImpl();
        Map<String,Object> map=new HashMap<>();
        int row=stationDao.updateState(id,status);
        if (row>0){
            map.put("code",200);
            map.put("message","修改成功");
        }else {
            map.put("code",300);
            map.put("message","修改失败");
        }
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
